package com.ssh;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class RemoveDuplicates_26 {
	public int removeDuplicates(int[] nums) {
		Set<Integer> set = new HashSet<Integer>();
        for (int i = 0; i < nums.length; i++) {
        	set.add(nums[i]);
        }
        Iterator<Integer> i = set.iterator();
        for (int j = 0; i.hasNext(); j++) {
        	nums[j] = i.next();
        }
        Arrays.sort(nums);
        return set.size();
    }
	
	public int removeDuplicates1(int[] nums) {
		int i = nums.length != 0 ? 1 : 0;
		for (int n : nums) {
			if (n > nums[i-1]) {
				nums[i++] = n;
			}
		}
		return i;
	}
}
